#region Summary

// 
// Owner : JackieHan 
// 
// Solution : Skomart.Spider 
// 
// Project : Jackie.Utility
// 
// File : ObjectConversionConfig.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 单个对象配置信息
// 
// History : 
//			2010-10-09 10:29:50	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using System.Xml;
using Jackie.Utility.CustomException;

#endregion

namespace Jackie.Utility.BvConversion
{
    /// <summary> 
    /// 单个对象配置信息
    /// </summary>
    public class ObjectConversionConfig
    {
        public const string NodeName = "Conversion";
        public const string BusinessTypeAttr = "businessType";
        public const string ViewTypeAttr = "viewType";

        public ObjectConversionConfig(XmlNode node)
        {
            if(!node.Name.Equals(NodeName))
                throw new XmlNodeErrorException(node.Name, NodeName);
            if(node.Attributes[BusinessTypeAttr]==null)
                throw new XmlAttributeNotFoundException(BusinessTypeAttr);
            if(node.Attributes[ViewTypeAttr]==null)
                throw new XmlAttributeNotFoundException(ViewTypeAttr);

            this.BusinessType = node.Attributes[BusinessTypeAttr].Value;
            this.ViewType = node.Attributes[ViewTypeAttr].Value;
            this.PropertyConfigs = new List<PropertyConfig>();

            foreach (XmlNode propertyNode in node.ChildNodes)
            {
                PropertyConfig propertyConfig = new PropertyConfig(propertyNode);
                this.PropertyConfigs.Add(propertyConfig);
            }
        }

        public ObjectConversionConfig(string businessTypeName,string viewTypeName)
        {
            this.BusinessType = businessTypeName;
            this.ViewType = viewTypeName;
            this.PropertyConfigs = new List<PropertyConfig>();
        }

        public string BusinessType { get; private set; }
        public string ViewType { get; private set; }
        public IList<PropertyConfig> PropertyConfigs { get; private set; }
    }
}